package com.tree.backend.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 创建更新时间自动填充
 */
@Component
public class MetaObjectHandlerImpl implements MetaObjectHandler {

    //在需要自动填充的属性上添加 @TableField(fill = FieldFill.INSERT)
    @Override
    public void insertFill(org.apache.ibatis.reflection.MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(org.apache.ibatis.reflection.MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}